package leetcode

// https://leetcode.com/problems/binary-search/
func search(nums []int, target int) int {
	left, right := 0, len(nums)-1
	for mid := left + (right-left)/2; left <= right; mid = left + (right-left)/2 {
		if nums[mid] == target {
			return mid
		} else if nums[mid] > target {
			right = mid - 1
		} else if nums[mid] < target {
			left = mid + 1
		}
	}
	return -1
}
